package com.gao.autowired.constructor;

import com.gao.autowired.AllWantBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 *
 * @author GaoXi
 * @date 2022/2/24 19:37
 */
@Component
public class ConstructorTest2 {
    private AllWantBean allWantBean;

    private String name;

    public ConstructorTest2() {
    }

    /**
     * 只有一个构造方法可以加
     * @param allWantBean
     * @param name
     */
/*    @Autowired
    public ConstructorTest2(AllWantBean allWantBean, String name) {
        this.allWantBean = allWantBean;
        this.name = name;
    }*/

    /**
     * 构造方法上即使没有@Autowired 5.1以后也可以用
     * @param allWantBean
     */
    @Autowired
    public ConstructorTest2(AllWantBean allWantBean) {
        this.allWantBean = allWantBean;
    }

    @Override
    public String toString() {
        return "ConstructorTest1{" +
            "allWantBean=" + allWantBean +
            '}';
    }
}
